<?php


namespace App\Http\Controllers\WebApi;

use App\Models\ImOperationLogs;
use Illuminate\Http\Request;

class OperationLogsController
{
    public function logList(Request $req)
    {
        $searchWord = $req->get('searchWord');
        $type = $req->get('type');
        list($offset, $limit, $page, $pagesize) = ImOperationLogs::pageProcess();
        $query = ImOperationLogs::with(['operator']);
        if (!empty($searchWord)) {
            $query->whereHas('operator', function ($sql) use ($searchWord) {
                $sql->where('username', 'like', $searchWord . '%')->orWhere('phone', $searchWord);
            });
        }
        if ($type > 0) {
            $query->where('type', $type);
        }
        $total = $query->count();
        $data = $query->offset($offset)->limit($limit)->orderBy('id', 'desc')->get();
        return okBack($data, [
            'total' => $total,
            'page' => $page,
            'pagesize' => $pagesize,
        ]);
    }
}
